﻿@{
    ViewBag.Title = "ImportLead";
    Layout = "~/Views/Shared/_Layout..cshtml";
}
@*<script src="@Url.Content("~/Scripts/jquery.ui.widget.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.iframe-transport.js")" type="text/javascript"></script>*@
@*<script src="@Url.Content("~/Scripts/jquery.fileupload.js")" type="text/javascript"></script>*@

<script type="text/javascript">

    function triggerFileUpload() 
    {
        document.getElementById("fileupload").click();
    }

    $(function ()
     {

         $('#fileupload').bind('change', function ()
         {   
            var filesize = this.files[0].size;
            var extention = this.files[0].name.substring((this.files[0].name.lastIndexOf('.')+1),this.files[0].name.length);


            if (extention == "xls" || extention == "xlsx" || extention == "csv") {
              if (filesize < 4194304)
               {

                   $('#Ms_successful').text("");
                   $('#Ms_successful').css("display", "block");
                   $('#Ms_successful').append("Selected FileName:" + this.files[0].name + "<a id='DeleteFile' class='btn btn-x'>X</a>");

                   /*to be disable click on "upload leads" button*/
                   $('#btnupload').removeClass('btn-upload-leads');
                   $('#btnupload').attr("onclick", "");
                   $('#btnupload').addClass('btn-upload-leads-gray');
                   /*to be able click on "Continue" button*/
                   $('#BtnContinue').removeClass('btn-continue-gray');
                   $('#BtnContinue').addClass('btn-continue-blue');

                   $('#DeleteFile').click(
                     function()
                     {
                         $('#Ms_successful').css("display", "none");
                         $('#btnupload').removeClass('btn-upload-leads-gray');
                         $('#btnupload').addClass('btn-upload-leads');
                         $('#btnupload').attr("onclick", "triggerFileUpload()");

                         /*to be able click on "Continue" button*/
                         $('#BtnContinue').removeClass('btn-continue-blue');
                         $('#BtnContinue').addClass('btn-continue-gray');
                        
                     }
                   )
                   

               }
               else
               {
                   var mess = "* Uploaded file size can not exceed 4MB";
                   $('#Ms_successful').text("");
                   $('#Ms_successful').css("display", "block");
                   $('#Ms_successful').append(this.files[0].name + "(" + mess + ")" + "<a id='DeleteFile' class='btn btn-x'>X</a>");
                   /*to delete selected file*/
                   $('#DeleteFile').click(
                     function () 
                     {
                         $('#Ms_successful').css("display", "none");
                         $('#btnupload').attr("onclick", "triggerFileUpload()");
                        /*to be able click on "Continue" button*/
                         $('#BtnContinue').removeClass('btn-continue-blue');
                         $('#BtnContinue').addClass('btn-continue-gray');
                     }
                   )

               }
               }
            else
            {
                var mess = "Only xls, xlsx, or csv files are allowed";
                $('#Ms_successful').text("");
                $('#Ms_successful').css("display", "block");
                $('#Ms_successful').append(this.files[0].name + "(" + mess + ")" + "<a id='DeleteFile' class='btn btn-x'>X</a>");

                /*to delete selected file*/
                $('#DeleteFile').click(
                     function () {
                         $('#Ms_successful').css("display", "none");
                         $('#btnupload').attr("onclick", "triggerFileUpload()");
                         /*to be able click on "Continue" button*/
                         $('#BtnContinue').removeClass('btn-continue-blue');
                         $('#BtnContinue').addClass('btn-continue-gray');
                     }
                   )
            }

             });

         });
         
         /*to post the seleted file*/
         function ContinueClick() 
         {
             //document.getElementById("UploadFile").click();
             init_importlead();
         }


         function init_importlead() {
             $.fancybox($('#popup-processing-importleads'), {
                 padding: 0,
                 closeBtn: false,
                 helpers: {
                     overlay: {
                         opacity: 0.8,
                         css: {
                             'background-color': '#11619d'
                         }
                     }
                 }
             });
         }

    </script>

<form class="form" action="/Lead/UploadLeads" method="post" enctype="multipart/form-data">
     @Html.Partial("UploadFile");
     @* @Html.Partial("MatchHeaders");
     @Html.Partial("ReviewAndImportLead");*@

</form>
